package com.gujiangbo.juc;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/6/13 20:23
 * @Version: 1.0
 * @Description:
 */
public class AtomicDemo {

    public static void main(String[] args) {
        Student student = new Student("小米",23);
        AtomicStampedReference<Student> atSp = new AtomicStampedReference<>(student,1);
        System.out.println(atSp.getReference());
        System.out.println(atSp.getStamp());

        Student student2 = new Student("华为",25);
        System.out.println(atSp.compareAndSet(student, student2, 1, 2));
        System.out.println(atSp.getReference());
        System.out.println(atSp.getStamp());

    }
}


class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}